<html>
<head></head>
<body>
See most often used API classes and code examples below.

<h1>Most often used API classes</h1>

<h3>Creating runtimes and clients</h3>

<a href="bt/Bt.html">Bt</a><br/>
<a href="bt/runtime/BtRuntime.html">BtRuntime</a><br/>
<a href="bt/runtime/BtRuntimeBuilder.html">BtRuntimeBuilder</a><br/>
<a href="bt/TorrentClientBuilder.html">TorrentClientBuilder</a><br/>
<a href="bt/runtime/BtClient.html">BtClient</a><br/>

<h3>Configuring runtime parameters</h3>

<a href="bt/runtime/Config.html">Config</a><br/>

<h3>Programmatically creating magnet links</h3>

<a href="bt/magnet/MagnetUri.html">MagnetUri</a><br/>

<h3>Programmatically creating .torrent files</h3>

<a href="bt/torrent/maker/TorrentBuilder.html">TorrentBuilder</a><br/>

<h3>Subscribing to runtime events</h3>

<a href="bt/event/EventSource.html">EventSource</a><br/>

<h1>Usage examples</h1>

<h3>Download a torrent from a magnet link</h3>
<hr/>
<blockquote>
// enable multithreaded verification of torrent data<br/>
Config config = new Config() {<br/>
&nbsp;&nbsp;&nbsp;&nbsp;@Override<br/>
&nbsp;&nbsp;&nbsp;&nbsp;public int getNumOfHashingThreads() {<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return Runtime.getRuntime().availableProcessors() * 2;<br/>
&nbsp;&nbsp;&nbsp;&nbsp;}<br/>
};<br/>
<br/>
// enable bootstrapping from public routers<br/>
Module dhtModule = new DHTModule(new DHTConfig() {<br/>
&nbsp;&nbsp;&nbsp;&nbsp;@Override<br/>
&nbsp;&nbsp;&nbsp;&nbsp;public boolean shouldUseRouterBootstrap() {<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return true;<br/>
&nbsp;&nbsp;&nbsp;&nbsp;}<br/>
});<br/>
<br/>
// get download directory<br/>
Path targetDirectory = Paths.get(System.getProperty("user.home"), "Downloads");<br/>
<br/>
// create file system based backend for torrent data<br/>
Storage storage = new FileSystemStorage(targetDirectory);<br/>
<br/>
// create client with a private runtime<br/>
BtClient client = Bt.client()<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;.config(config)<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;.storage(storage)<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;.magnet("magnet:?xt=urn:btih:af0d9aa01a9ae123a73802cfa58ccaf355eb19f1")<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;.autoLoadModules()<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;.module(dhtModule)<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;.stopWhenDownloaded()<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;.build();<br/>
<br/>
// launch<br/>
client.startAsync().join();
</blockquote>
<hr/>
<h3>Create a torrent</h3>
<hr/>
<blockquote>
Path torrentRoot = Paths.get("/home/torrents/mytorrent");<br/>
Path file1 = Paths.get("/home/torrents/mytorrent/file1.bin");<br/>
Path file2 = Paths.get("/home/torrents/mytorrent/file2.bin");<br/>
Path dirToAdd = Paths.get("/home/torrents/mytorrent/dir_with_files");<br/>
byte[] torrentBytes = new TorrentBuilder()<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;.rootPath(torrentRoot)<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;.addFiles(file1, file2, dirToAdd)<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;.announce("http://example.com/announce")<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;.build();<br/>
Files.write(Paths.get("/home/torrents/mytorrent.torrent"), torrentBytes);
</blockquote>
<hr/>
</body>
</html>
